package com.bmps.springcloud.insuredmicroservice.service.trial.strategy;

import com.bmps.springcloud.common.utils.DateUtil;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.UnderWriteConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.InsurantModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.RequestModel;
import com.bmps.springcloud.insuredmicroservice.model.trail.TrialPersonModel;
import com.bmps.springcloud.insuredmicroservice.service.RedisService;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author Administrator
 * @date 2020/12/22 16:50
 */
public class Llt030TrialStrategy implements TrialStrategy {
    @Override
    public TrialPersonModel premiumTrialCalculationPrepare(ProductModel productModel, RequestModel requestModel, RedisService redisService) {
        List<InsurantModel> insurantModelList = requestModel.getCustInfo().getInsurants().getInsurant();
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), insurantModelList);
        String payIntv = requestModel.getProductInfo().getPayIntv();
        String prodCode = productModel.getProdCode();
        TrialPersonModel trialPersonModel = new TrialPersonModel();
        trialPersonModel.setRiskCode(prodCode);
        trialPersonModel.setGet(productModel.getAmnt());
        trialPersonModel.setPayIntv(payIntv);
        if (StringUtils.equals(UnderWriteConstant.MONTH_PAY, payIntv)) {
            trialPersonModel.setPayIntvRate("0.085");
        } else {
            trialPersonModel.setPayIntvRate("1");
        }
        trialPersonModel.setAppAge(DateUtil.getYears(insurantModel.getBirthday(), requestModel.getPolicyInfo().getPolApplyDate()));
        trialPersonModel.setSex(insurantModel.getSex());
        trialPersonModel.setReNewCharge("1");

        return redisService.getCalculateModeNew(trialPersonModel, AcceptConstant.CALCULATION_TYPE_G);
    }

}
